<?php
namespace frontend\controllers;
use yii;
use common\models\Post;
use common\models\PostComment;
use common\models\Friendlink;

use yii\data\Pagination;
use yii\helpers\Url;
/**
 * Post controller
 */
class HelpController extends FController
{

 public function actionView()
    {
        $id = (int)Yii::$app->request->get('id');

        $cache = Yii::$app->cache;

        if(!$id){
            exit("The Content You Requested Does't Exist");
        }

        $model = Post::findOne($id);
        //$m=Post::find()->where(['post_category_id'=>$model->post_category_id])->all();
        //$parent = Post::itemAlias('post_category_id',$model->post_category_id);
        //$parent_name = json_encode(trim(explode('-', $parent)[1]));

        //左侧导航的查询和分配
        

        // 尝试从缓存中取回 $data 
        $footer_list = $cache->get('footer_list');
        if ($footer_list === false) {

            $footer_list[0] = Post::itemAlias('post_category_id');

            foreach ($footer_list[0] as $k => $v) {
                $footer_list[1][$k] = Post::find()->select('id,title')
                                    ->where("status = 1 AND post_category_id =".$k)
                                    ->asArray()->all();
            }
            $cache->set('footer_list', $footer_list);
        }
        Yii::$app->view->params['page']['page_title'] = '帮助中心 - ' . $this->w_config['website_name'];
        return $this->render('view', [
            'model' => $model,
            'footer_list' => $footer_list
        ]);
        
     }


}

